package com.shengyuan.manage_os.old.ying.erpm;

import org.json.JSONException;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapView;
import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.GpsButton;
import com.shengyuan.manage_os.old.ying.erpm.controls.PictureButton;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Actual_OA_QingJia extends BaseActivity{

	protected PictureButton PictureButton_myself;
	protected EditText editText_shiyou,editText_shichang;
	private BaiduMap aMap;
	private MapView mapView;
//	private OnLocationChangedListener mListener;
//	private LocationManagerProxy mAMapLocationManager;
	

	@Override
	public void onClick(View view) {
		super.onClick(view);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actual_oa_qingjia);
		InitControls();
//
//		MapsInitializer.sdcardDir =MapUtility.getOfflineMapPath();
		mapView = (MapView) findViewById(R.id.map);
//		mapView.onCreate(savedInstanceState);// 此方法必须重写
		//init();
	}
	private void init() {
		GpsButton.pAMapLocation = null;
		if (aMap == null) {
			aMap = mapView.getMap();
		}
	}

	@Override
	protected void SaveJsonData() {
		try {
			IsJson1 = true; mFinished = 1; mPrintenabled= 0;
			JsonMyID();
			getDataExt();
			
			getCurrentUser();		
			getMemo();
			JsonPicture_Ext();
		}catch (Exception e) {
		}
	}
	
	protected void getDataExt() throws JSONException {
//		double x = GpsButton.pAMapLocation.getLatitude() ;
//		double y = GpsButton.pAMapLocation.getLongitude();
//		Bundle bundle = GpsButton.pAMapLocation.getExtras();
//		String s = bundle.get("desc").toString();
		mJson.put( getString(R.string.title_actual_oa_shiyou), editText_shiyou.getText().toString());
		mJson.put( getString(R.string.title_actual_oa_shichang), editText_shichang.getText().toString());
	}
	
	protected void JsonPicture_Ext() throws JSONException {
		if (PictureButton_myself!=null) {
			mJson.put( getString(R.string.title_actual_form_myself), PictureButton_myself.mFileName);
		}
	}	
	@Override
	protected void SaveSelfPic(String sPath) {
		try {
			CopyPicDest(PictureButton_myself, sPath);
		} catch (Exception e) {
			Utility.MessageBox(this,e.getMessage());
		}
	}

	@Override
	public void Back() {
		super.Back();
	}

	@Override
	public void InitControls() {
		super.InitControls();
		PictureButton_myself = (PictureButton) findViewById(R.id.PictureButton_myself);
		editText_shiyou = (EditText) findViewById(R.id.editText_shiyou);
		editText_shichang = (EditText) findViewById(R.id.editText_shichang);
	}
	
	@Override
	public Boolean IsPassed() {
		if (super.IsPassed()) {
			if (!PictureButton_myself.IsExist()) {
				Utility.MessageBox(this, PictureButton_myself.FIELD );
				return false;
			}			
			if (!CheckEditStringMin5(editText_shiyou)) {
				return false;
			}
			if (!CheckEditStringMin5(editText_shichang)) {
				return false;
			}			
//			if (GpsButton.pAMapLocation==null ) {
//				Utility.MessageBox( GpsButton_Gps.hint );
//				return false;
//			}
//			else
				return true;
		}else {
			return false;
		}
	}
	@Override
	protected void onResume() {
		super.onResume();
		PictureButton_myself.postInvalidate();
		mapView.onResume();
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onPause() {
		super.onPause();
		mapView.onPause();
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		mapView.onSaveInstanceState(outState);
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onDestroy() {
		super.onDestroy();
		mapView.onDestroy();
	}



}
